package com.ymttest.utils.compare;

import org.apache.commons.lang.exception.ExceptionUtils;

import com.ymttest.utils.FileUtil;
import com.ymttest.utils.YMTDateUtil;

public class LoggerHelper implements LoggerInterface   {
	private LogPathConf logPathConf;
	
	public LoggerHelper(){
		this.logPathConf = new LogPathConf();
	}
	
	public LoggerHelper(LogPathConf logPathConf){
		this.logPathConf = logPathConf;
	}
	
	
	public  void verifyIsNull(Object obj, String desc) {
		if (obj != null && obj != "null" && obj.toString().length() != 0) {
			writeResult(logPathConf.getDiffPath(), desc);
		} else {
			//writeResult(logPathConf.getInfoPath(), desc);
		}
	}

	public  void verifyNotNull(Object obj, String desc) {
		if (obj != null && obj != "null" && obj.toString().length() != 0) {
			//writeResult(logPathConf.getInfoPath(), desc);
		} else {
			writeResult(logPathConf.getDiffPath(), desc);
		}
	}

	public  void verifyEquals(Object expected, Object actual, String desc) {
		if (expected != null && actual != null) {
			if (expected.equals(actual)) {
				writeResult(logPathConf.getInfoPath(), desc);
			} else {
				writeResult(logPathConf.getDiffPath(), desc);
			}
		} else if (expected == actual) {
			writeResult(logPathConf.getInfoPath(), desc);
		} else {
			writeResult(logPathConf.getDiffPath(), desc);
		}
	}

	public  void failure( String desc){
		writeResult(logPathConf.getErrorPath(), desc);
	}
	
	public  void comment( String desc){
		writeResult(logPathConf.getInfoPath(), desc);
		if (logPathConf.getInfoPath() == null || logPathConf.getInfoPath().equals("")) {
			// no name or name empty, do nothing
		} else {
			System.out.println(desc);
		}
		//writeResult(logPathConf.getDiffPath(), desc);
		//writeResult(logPathConf.getErrorPath(), desc);
	}
	
	
	
	
	public  static void writeResult(String filePath, String desc) {
		if (filePath == null || filePath.equals("")) {
			// no name or name empty, do nothing
		} else {
			FileUtil.writeAsLine(filePath, YMTDateUtil.getSysTime() + ","+desc);
			//FileUtil.writeAsLine(filePath, desc);
		}

	}

	@Override
	public void failure(String desc, Exception e) {
		writeResult(logPathConf.getErrorPath(), desc);
		writeResult(logPathConf.getErrorPath(), ExceptionUtils.getFullStackTrace(e));
		
	}
	
	
	

}
